package com.eshop.inventory.mapper;

import com.eshop.inventory.model.ProductInventory;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author: Xukai
 * @description: 库存数量Mapper
 * @createDate: 2018/7/23 14:05
 * @modified By:
 */
public interface ProductInventoryMapper {

    /**
     * 根据商品id查询商品库存信息
     *
     * @param productId 商品id
     * @return 商品库存信息
     */
    @Select("select * from product_inventory where product_id = #{productId, jdbcType=INTEGER}")
    @Results({
            @Result(column = "product_id", property = "productId"),
            @Result(column = "inventory_cnt", property = "inventoryCnt"),
    })
    ProductInventory findProductInventory(Integer productId);

    /**
     * 更新库存数量
     *
     * @param productInventory 商品库存
     */
    @Update("update product_inventory set inventory_cnt = #{inventoryCnt} where product_id = #{productId}")
    void updateProductInventory(ProductInventory productInventory);


}
